import * as Cesium from 'cesium/Cesium';

export default class Catesian3Math{

    /**
     * 屏幕坐标转换成三维坐标
     * @param {*} px 
     * @param {*} viewer 
     * @returns 
     */
    static getCatesian3FromPX(px, viewer) {
        var picks = viewer.scene.drillPick(px);
        viewer.render();
        var cartesian;
        var isOn3dtiles = false;
        for (var i = 0; i < picks.length; i++) {
            if (picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
                isOn3dtiles = true;
            }
        }
        if (isOn3dtiles) {
            cartesian = viewer.scene.pickPosition(px);
        } else {
            var ray = viewer.camera.getPickRay(px);
            if (!ray) return null;
            cartesian = viewer.scene.globe.pick(ray, viewer.scene);
        }
        console.log(px,cartesian)
        return cartesian;
    }
}